<?php
require_once 'Zend/View/Interface.php';
class Zend_View_Helper_AuthInfo extends Zend_View_Helper_Abstract
{
    /**
     *
     * @var Storefront_Service_Authentication 
     */
    protected $_authService;
    
    /**
     * Usage:
     * 1) $this->authinfo('role') or $this->authinfo('firstname') to get the role 
     *    or firstname of the currently authenticated user or null if are not logged in
     * 2) $this->authinfo()->isLoggedIn() returns TRUE if they are logged false 
     *    or FALSE if they are not
     *
     * @param string $info | null
     * @return Zend_View_Helper_AuthInfo 
     */
    public function AuthInfo($info = NULL)
    {
        if (NULL === $this->_authService) {
            $this->_authService = new Storefront_Service_Authentication();
        }
        if (NULL === $info) {
            return $this;
        }
        if (FALSE === $this->isLoggedIn()) {
            return NULL;
        }
        return $this->_authService->getIdentity()->$info;
    }
    
    public function isLoggedIn()
    {
        return $this->_authService->getAuth()->hasIdentity();
    }
}